unit UsuarioSearchFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, Buttons, StdCtrls, DBCtrls, MainSearchFr;

type

  { TUsuarioSearchFrame }

  TUsuarioSearchFrame = class(TMainSearchFrame)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    id_usuario: TEdit;
    id_pessoa: TEdit;
    nome_pessoa: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    ativo: TRadioGroup;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure LocalizarButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

implementation

uses Initializator, UsuarioDM, QueryConditions, MainFr;

{ TUsuarioSearchFrame }

procedure TUsuarioSearchFrame.BitBtn1Click(Sender: TObject);
begin
  TheControl.ShowForeignFrame(TMainFrame(PessoaSearchFrame));
end;

procedure TUsuarioSearchFrame.BitBtn2Click(Sender: TObject);
begin
   TheControl.ShowFrame(TMainFrame(UsuarioRecordFrame));
end;

procedure TUsuarioSearchFrame.LocalizarButtonClick(Sender: TObject);
var
  condicoes: TQueryConditions;
  m: string;
begin
  if ativo.ItemIndex = 0 then begin
    m := 'A';
  end else begin
    m := 'I';
  end;
  condicoes := TQueryConditions.Create(CON_AND);
  condicoes.AddJoinField('u.id_usuario', 'p.id_pessoa');
  condicoes.Add('u.id_usuario', id_usuario.Text);
  condicoes.Add('p.id_pessoa', id_pessoa.Text);
  condicoes.AddText('p.nome_pessoa', nome_pessoa.Text);
  condicoes.AddText('ativo', m);
  UsuarioData.Search(condicoes, 'usuario as u, pessoa as p');
end;

initialization
  {$I usuariosearchfr.lrs}

end.

